<template>
  <div class="page-main">
    <group class="page-main-head">
      <cell>
        <div slot="title"
             class="page-main-head-title">
              {{inviteBidData[0].InviteBidTopic}}
        </div>
        <div slot="inline-desc"
             class="page-main-head-section">
            <span>发布日期:
            <strong style="color: #000000;font-size:14px">{{inviteBidData[0].EmitBidTime|formatDate}}</strong>
          </span>
        </div>
      </cell>
    </group>
    <group class="page-main-content">
      <cell class="page-main-content-titile">
        <div slot="title">
          <span class="div-name-span"></span>
          <strong style="font-size:16px">当前进展</strong>
        </div>
      </cell>
      <cell class="page-main-content-section">
        <div slot="title">
          <timeline :currentIndex="currentIndex" :isStop="isStop">
            <timeline-item :title="'报名'"
                           :desc="handleBMData"></timeline-item>
            <timeline-item :title="'入围'"
                           :desc="handleRWData"></timeline-item>

            <timeline-item :title="'发标'"
                           :desc="handleFBData"></timeline-item>
            <timeline-item :title="'标书下载'"
                           :desc="handleBSXZData"></timeline-item>
            <timeline-item :title="'回标'" :desc="handleHBData"></timeline-item>
            <timeline-item :title="'定标'" :desc="handleDBData"></timeline-item>
            <timeline-item :title="'签约'" :desc="handleQYData"></timeline-item>
          </timeline>
        </div>
      </cell>
    </group>
    <div class="page-main-content-footer">
      <x-button type="warn"
                @click.native="onlineAnswer" class="bottom-button-red">
        在线答疑
      </x-button>
    </div>

  </div>

</template>

<script>
  import { Search, Tab, TabItem, Group, Cell, XButton } from 'vux'
  import { MyInviteBidService } from '../../service/Services.js'
  // import _ from 'lodash'
  import { TimelineItem, Timeline } from '../../components/timeline'
  import Vue from 'vue'

  export default {
    name: 'CellBtn',
    components: {
      Search,
      Tab,
      TabItem,
      Group,
      Cell,
      XButton,
      Timeline,
      TimelineItem
    },
    data () {
      return {
        searchText: '',
        pageData: [],
        inviteBidData: [{InviteBidTopic: '', EmitBidTime: '/Date(1414411096387+0800)/'}], // 招标预告数据
        handleBMData: [], // 报名
        handleRWData: [], // 入围
        handleFBData: [], // 发标
        handleBSXZData: [], // 下载标书
        handleHBData: [], // 回标
        handleDBData: [], // 定标
        handleQYData: [], // 签约
        currentIndex: 0,
        isStop: false
      }
    },
    methods: {
      loadData () {
        this.$vux.loading.show({
          text: '加载中...'
        })
        let providerGUID = this.$store.getters.getUserInfo.ProviderGUID
        let cgPlanGUID = this.$route.query.CgPlanGUID
        let inviteBidForenoticeGUID = this.$route.query.InviteBidForenoticeGUID
        let formatDate = Vue.filter('formatDate')
        MyInviteBidService.GetInviteBidForenotice(inviteBidForenoticeGUID).then((res) => {
          this.inviteBidData = res.Data
        })
        MyInviteBidService.HandleBM(providerGUID, cgPlanGUID).then((res) => {
          this.$vux.loading.hide()
          if (res.Data.length > 0) {
            this.currentIndex = 1
            this.handleBMData.push('报名日期:' + formatDate(res.Data[0].FinalistMsgTime))
            MyInviteBidService.HandleRW(providerGUID, cgPlanGUID).then((res) => {
              this.$vux.loading.hide()
              if (res.Data.length > 0) {
                this.currentIndex = 2
                this.handleRWData.push('发布日期:' + formatDate(res.Data[0].FinalistMsgTime))
                MyInviteBidService.handleFB(providerGUID, cgPlanGUID).then((res) => {
                  this.$vux.loading.hide()
                  if (res.Data.length > 0) {
                    this.currentIndex = 3
                    this.handleFBData.push('发标日期:' + formatDate(res.Data[0].EmitBidTime))
                    this.handleFBData.push('回标截止日期:' + formatDate(res.Data[0].EndBidTime))
            // 下载标书
                    MyInviteBidService.handleBSXZ(providerGUID, cgPlanGUID).then((res) => {
                      if (res.Data.length > 0) {
                        this.currentIndex = 4
                        this.handleBSXZData.push('标书下载日期:' + formatDate(res.Data[0].BidDownloadTime))
                        this.handleBSXZData.push('回标截止日期:' + formatDate(res.Data[0].EndBidTime))
                // 回标
                        MyInviteBidService.handleHB(providerGUID, cgPlanGUID).then((res) => {
                          if (res.Data.length > 0 && res.Data[0].ReturnBidTime) {
                            // 判断是否放弃回标
                            if (res.Data[0].Status === '已放弃回标') {
                              this.isStop = true
                            } else {
                              this.currentIndex = 5
                            }
                            this.handleHBData.push('回标日期:' + formatDate(res.Data[0].ReturnBidTime))
                    // 定标
                            MyInviteBidService.handleDB(providerGUID, cgPlanGUID).then((res) => {
                              if (res.Data.length > 0) {
                                this.currentIndex = 6
                                this.handleDBData.push('中标日期:' + formatDate(res.Data[0].ZBTime))
                        // 签约
                                MyInviteBidService.handleQY(providerGUID, cgPlanGUID).then((res) => {
                                  if (res.Data.length > 0) {
                                    this.currentIndex = 7
                                    let formatMoney = Vue.filter('formatMoney')

                                    this.handleQYData.push('合同名称:' + res.Data[0].ContractName)
                                    this.handleQYData.push('合同金额:' + formatMoney(res.Data[0].HtAmount) + '元')
                                    this.handleQYData.push('签约日期:' + formatDate(res.Data[0].SignDate))
                                  }
                                })
                              }
                            })
                          }
                        })
                      }
                    })
                  }
                })
              }
            })
          }
        })
      },
      onlineAnswer () {
        if (!this.$route.query.InviteBidGUID) {
          this.$vux.toast.show({
            text: '未发标的预告暂不支持答疑',
            type: 'cancel',
            width: '180px'
          })
        } else {
          this.$router.push({path: '/demos/invite-bid-question',
            query: {InviteBidForenoticeGUID: this.$route.query.InviteBidForenoticeGUID,
              InviteBidGUID: this.$route.query.InviteBidGUID,
              CgPlanGUID: this.$route.query.CgPlanGUID}
          })
        }
      }
    },
    computed: {
      // getResult () {
      //   return _.filter(this.pageData, item => {
      //     return item.ForenoticeTitle.indexOf(this.searchText) !== -1 ||
      //       item.Status.indexOf(this.searchText) !== -1
      //   })
      // }
    },
    created () {
      this.loadData()
    }
  }
</script>
<style scoped lang="less">
  .page-main {
    font-family: PingFangSC-Regular;
    letter-spacing: 0;
    .page-main-head {
      .page-main-head-title {
        font-size: 18px;
        color: #000000;
        font-weight: bold;
      }
    }
    .page-main-content-titile {
      .div-name-span {
        display: inline-block;
        height: 25px;
        width: 4px;
        background: #DC220B;
        position: relative;
        top: 6px;
        margin-right: 10px;
      }
    }
    .page-main-content-section {
      font-family: PingFangSC-Regular;
      font-size: 15px;
      .step-complate {
        color: #62AC5E;
      }
    }
    .page-main-content-footer {
      position: relative;
      bottom: 0px;
    }
  }
   .bottom-button-red {
    box-shadow: 0px -2px 2px 0px rgba(0, 0, 0, 0.05);
    border-top: 1px solid #e5e3e6;
    position: fixed;
    bottom: 0;
    left: 0;
    color: white;
    background-color: red;
    z-index: 999;
    border-radius: 0px;
  }
</style>
